package editors.gui;
import graphics.system.GLTools;
import tools.Point;
public class GuiCheckbox extends GuiObject {
	private boolean checked;
	private String name;
	public GuiCheckbox(Point pos, String name) {
		super();
		this.rect = new Rect(pos.add(new Point(GuiSettings.LINEHEIGHT / 2, -GuiSettings.LINEHEIGHT / 2)), GuiSettings.LINEHEIGHT, GuiSettings.LINEHEIGHT);
		this.checked = false;
		this.name = name;
	}
	@Override
	public boolean isClicked() {
		return clicked;
	}
	@Override
	public boolean checkClick(Point mp) {
		if (rect.isIn(mp)) {
			this.checked = !this.checked;
			clicked = true;
		}
		return clicked;
	}
	@Override
	public void draw() {
		rect.draw(GuiSettings.BUTTON_OFF_COL);
		if (checked) {
			GLTools.drawRect(rect.getCenter(), rect.getWidth() - 10, rect.getHeight() - 10, 0, GuiSettings.CHECKBOX_CHECKED);
		}
		Point s = rect.getTopLeft();
		s.sAdd(new Point(GuiSettings.LINEHEIGHT + 2, -GuiSettings.FONTADJUST));
		GLTools.drawText(s, name, GuiSettings.TEXT_COL, GuiSettings.FONTSIZE);
	}
	public boolean isChecked() {
		return checked;
	}
	public void setChecked(boolean v) {
		this.checked = v;
	}
}
